﻿using System;

namespace cSharpHomework2_4
{
    class Program
    {
        static void Main(string[] args)
        {
            shape a = new rectangle(1, 2);
            shape b = new Square(1);
            shape c = new triangle(5, 6);
            Console.WriteLine(a.GetArea());
            Console.WriteLine(a.IsValid());
            Console.WriteLine(b.GetArea());
            Console.WriteLine(b.IsValid());
            Console.WriteLine(c.GetArea());
            Console.WriteLine(c.IsValid());
        }
        public interface shape
        {


            public double GetArea();
            public bool IsValid();
        }

        class rectangle : shape
        {
            int chang;
            int kuan;

            public rectangle(int a, int b)
            {
                chang = a;
                kuan = b;
            }
            public bool IsValid()
            {
                if (chang < 0 || kuan < 0)
                {
                    return false;
                }
                return true;
            }

            public double GetArea()
            {
                return chang * kuan;
            }
        }

        class Square : shape
        {
            int a;
            public Square(int a)
            {
                this.a = a;
            }
            double shape.GetArea()
            {
                return a * a;
            }

            bool shape.IsValid()
            {
                if (a < 0) { return false; } else return true;
            }
        }

        class triangle : shape
        {
            int kuan;
            int gao;

            public triangle(int a, int b)
            {
                kuan = a;
                gao = b;
            }
            public double GetArea()
            {
                return kuan * gao / 2;
            }

            public bool IsValid()
            {

                if (kuan < 0 || gao < 0)
                {
                    return false;
                }
                else return true;
            }
        }
    }
}
